- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
New Components - alegra #15125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Components - alegra #15125
Conversation
| The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
 | 
| WalkthroughThis pull request introduces a comprehensive set of components for the Alegra application, including actions for creating contacts and invoices, finding contacts, and webhook sources for tracking new clients, invoices, and items. The changes establish a robust integration with the Alegra API, providing methods for creating, searching, and monitoring various business entities with flexible configuration options. Changes
 Assessment against linked issues
 Possibly related PRs
 Suggested Reviewers
 Poem
 Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit: 
 Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
 Other keywords and placeholders
 CodeRabbit Configuration File ( | 
Sources - New Client (Instant) - New Invoice (Instant) - New Item (Instant) Actions - Create Contact - Create Invoice - Find Contact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (11)
components/alegra/sources/new-client-instant/new-client-instant.mjs (1)
1-3: Consider validating the necessity ofsampleEmitimport.
IfsampleEmitis solely used for testing purposes, consider importing it conditionally or extracting it to a test-only module to keep production code lean.components/alegra/actions/find-contact/find-contact.mjs (2)
1-2: Confirm app instance name matches naming conventions.
The app is imported asalegrafrom"../../alegra.app.mjs". In some codebases, the pattern is to use uppercase or a more descriptive name for clarity (e.g.,AlegraApp).
18-29: Leverage specialized error handling.
Currently, any network or usage error either fails silently or is caught by the outer pipeline. Consider adding user-friendly error messages or fallback logic.components/alegra/sources/new-item-instant/test-event.mjs (1)
32-55: Check inventory and subitem structures.
ThevariantAttributes,itemVariants, andsubitemsvalues arenull. If your code expects arrays or objects, ensure it safely handles null values to avoid runtime errors.components/alegra/sources/new-invoice-instant/test-event.mjs (1)
4-23: Use descriptive names for invoice properties.
Properties likeanotationandobservationscan become confusing. Consider renaming or clarifying their distinction in your code/documentation.components/alegra/sources/common/base.mjs (2)
3-9: Use descriptive component naming.
Although thedefaultexport is succinct, consider adding a clear name or key property for better readability and identification in logs or developer tools.
16-18: PlaceholdergetExtraData()method.
This returns an empty object for now. If your future roadmap includes optional query params or additional event data, you can expand this method.components/alegra/actions/create-contact/create-contact.mjs (1)
8-14: Action metadata is descriptive.
Use ofkey,name, anddescriptionstrongly conveys the purpose of this action.components/alegra/alegra.app.mjs (3)
7-151: Prop definitions with pagination.
All properties with anoptions({ page })function effectively handle pagination for listing. The repeated structure is consistent—suggest factoring out a shared function to reduce duplication.
175-237: Expanded set of methods for Alegra API coverage.
You cover multiple resources (contacts, invoices, sellers, etc.). Consider adding robust error handling for each request to catch network or authentication failures.
238-242: Webhook deletion method finalizes coverage.
Completes the webhook lifecycle. Again, consider checking for a validwebhookIdprior to deletion.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
- pnpm-lock.yamlis excluded by- !**/pnpm-lock.yaml
📒 Files selected for processing (14)
- components/alegra/actions/create-contact/create-contact.mjs(1 hunks)
- components/alegra/actions/create-invoice/create-invoice.mjs(1 hunks)
- components/alegra/actions/find-contact/find-contact.mjs(1 hunks)
- components/alegra/alegra.app.mjs(1 hunks)
- components/alegra/common/constants.mjs(1 hunks)
- components/alegra/common/utils.mjs(1 hunks)
- components/alegra/package.json(1 hunks)
- components/alegra/sources/common/base.mjs(1 hunks)
- components/alegra/sources/new-client-instant/new-client-instant.mjs(1 hunks)
- components/alegra/sources/new-client-instant/test-event.mjs(1 hunks)
- components/alegra/sources/new-invoice-instant/new-invoice-instant.mjs(1 hunks)
- components/alegra/sources/new-invoice-instant/test-event.mjs(1 hunks)
- components/alegra/sources/new-item-instant/new-item-instant.mjs(1 hunks)
- components/alegra/sources/new-item-instant/test-event.mjs(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- components/alegra/sources/new-client-instant/test-event.mjs
- components/alegra/package.json
🔇 Additional comments (38)
components/alegra/common/constants.mjs (5)
1-2: Confirm the default pagination limit.
It's great that you've introduced aLIMITconstant for pagination. However, verify if30is the best default for larger datasets.
3-6: Naming consistency looks good.
TheTYPE_OPTIONSarray follows self-explanatory naming, helping standardize contact types. No issues spotted.
8-11: Consistent naming for status options.
TheSTATUS_OPTIONSarray clearly distinguishes "active" from "inactive" statuses. This is straightforward and maintainable.
13-16: ExpandINVOICE_STATUS_OPTIONSif needed.
Currently supports "draft" and "open" statuses. If the Alegra API also expects additional statuses (e.g., "closed"), consider adding them here.
18-25: Future-proof your periodicity options.
The array ofPERIODICITY_OPTIONScovers many intervals. This is well-defined, but confirm all required intervals are captured.components/alegra/common/utils.mjs (4)
1-2: Confirm desired fallback behavior.
Returningundefinedfor a falsyobjmight be intentional. Ensure this aligns with usage patterns in your codebase.
4-14: Proper JSON parsing for array items.
Parses string items within arrays gracefully. This approach is good for flexible data handling.
16-22: Graceful handling of string inputs.
Catches JSON parsing errors and returns the original string, ensuring robust fallback behavior for unexpected inputs.
23-24: Clean final return logic.
Returning the originalobjis straightforward and ensures minimal transformation.components/alegra/sources/new-item-instant/new-item-instant.mjs (4)
4-12: Well-structured source definition.
Your source object composition (mergingcommonplus the unique config) is a standard, maintainable approach.
13-16: Clear event naming.
Returning"new-item"fromgetEventType()is explicit and easy to reference.
17-20: Meaningful event summary.
Usesitem.nameto create a succinct, user-friendly summary. Ensure thatitem.nameis always available or handle null/undefined names for resiliency.
21-21: Sample event included.
Including a sample event is helpful for testing and demonstration. No issues spotted.components/alegra/sources/new-invoice-instant/new-invoice-instant.mjs (4)
4-12: Consistent source structure.
Follows the same pattern as other instant sources, promoting consistency across your codebase.
13-16: Appropriate event naming.
"new-invoice"is self-descriptive and consistent with other sources.
17-20: Concise invoice summary.
Concise messaging for newly created invoices. Consider confirming thatinvoice.idalways exists or handle edge cases gracefully.
21-21: Sample event fosters clarity.
Providing a realistic sample insampleEmithelps users understand the event's structure and data fields.components/alegra/sources/new-client-instant/new-client-instant.mjs (1)
4-22: Handle missingclient.emailingetSummary.
Ifclient.emailis undefined or null, the template string could produce an undefined result. You might want to provide a fallback or validation.components/alegra/actions/find-contact/find-contact.mjs (1)
3-17: Ensure alignment with prop definitions.
Thequeryprop references"query"inpropDefinitions, so verify thatalegra.app.mjsindeed provides a matching definition and handles non-string inputs gracefully.components/alegra/sources/new-item-instant/test-event.mjs (2)
1-3: Review event naming consistency.
Thesubjectis"new-item". Ensure this naming is used consistently across your event source, emitter, and consumer logic.
4-31: Confirm correct usage of alphanumeric and non-ASCII characters.
The item name includes special characters:"Un Ítem / S". Verify that Alegra's API and your database properly handle UTF-8 or extended character sets.components/alegra/sources/new-invoice-instant/test-event.mjs (2)
1-3: Enforce consistent event naming.
Thesubjectis"new-invoice". Confirm that any consumer code is listening explicitly for"new-invoice"events.
24-49: Validate nested objects in the invoice structure.
The invoice references multiple nested IDs (estimate,costCenter,remission, etc.). Verify that each referenced entity exists or handle potential 404s or missing data.components/alegra/sources/common/base.mjs (5)
1-2: Good initial import.
You correctly import the alegra app reference, ensuring that the source can access necessary methods fromalegra.app.mjs.
10-15: Database methods follow best practices.
Storing and retrievinghookIdin the DB is straightforward and maintainable, ensuring data is persisted.
21-29: Webhook creation logic is clean.
The method splits the HTTP endpoint from an HTTPS-based string to send to the API. Ensure you handle edge cases if the URL scheme doesn't match “https://”.
30-34: Webhook deletion uses the stored ID.
This approach ensures you clean up properly. Consider validating thewebhookIdbefore sending the delete request to avoid potential undefined references.
35-47: Event emission logic is clear.
You parse the body, confirm the presence of amessagefield, and then derive the model data. The consistent use ofclient,item, orinvoiceis well-structured and easy to extend.components/alegra/actions/create-contact/create-contact.mjs (3)
1-7: Imports and helper usage are well-structured.
UsingparseObjectfrom../../common/utils.mjsensures consistent conversion and avoids JSON parsing errors.
15-138: Comprehensive prop definitions.
You’ve included a wide range of contact fields (phones, emails, addresses, etc.). This approach provides flexibility but can be prone to user misconfiguration.Consider adding client-side validation or default values for critical fields.
139-171: Structured data construction for contact creation.
You assemble nested objects (address, accounting, etc.) clearly. Good use of optional chaining with parse helpers in case some fields are not present.components/alegra/alegra.app.mjs (2)
1-2: Initial setup for axios and constants.
Pulling inaxiosfrom@pipedream/platformand theLIMITconstant suggests pagination is managed consistently across the codebase.
153-174: Authentication and base URL are well-defined.
The_baseUrl()and_auth()methods help maintain clarity and reduce code duplication.components/alegra/actions/create-invoice/create-invoice.mjs (5)
1-2: ConfigurationError import is apt.
This ensures that helpful user-facing errors get raised for misconfigurations.
3-7: Constants for invoice creation.
ImportingINVOICE_STATUS_OPTIONSandPERIODICITY_OPTIONSensures consistent usage of recognized enumerations.
8-13: Clear action metadata.
Providingkey,name,description, version, and type helps keep the code self-documenting.
14-153: Well-defined invoice props.
Users can specify a broad range of invoice characteristics (status, items, client, payments, etc.), offering a complete solution. Be mindful of large user input arrays to avoid performance bottlenecks.
154-192: Robust error handling in therunmethod.
You catch potential exceptions and throw a descriptiveConfigurationError. This is excellent for clarity. Consider adding detailed logging around partial invoice creation states if the API partially completes the request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
- components/alegra/actions/create-invoice/create-invoice.mjs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: pnpm publish
- GitHub Check: Verify TypeScript components
- GitHub Check: Lint Code Base
- GitHub Check: Publish TypeScript components
🔇 Additional comments (1)
components/alegra/actions/create-invoice/create-invoice.mjs (1)
11-11: Enhance the documentation link with more contextConsider adding more context about what users can expect to find in the documentation link.
- description: "Creates a new invoice in Alegra. [See the documentation](https://developer.alegra.com/reference/post_invoices)", + description: "Creates a new invoice in Alegra. [See the API documentation for all available fields and options](https://developer.alegra.com/reference/post_invoices)",
| /approve | 
Resolves #13261.
Summary by CodeRabbit
New Features
Improvements
Chores